PHP - Blank Row Being Inserted In Top Of Mysql.
Shouldn't the following stop a blank row from being inserted into mysql?
I have a description and a date but it still keeps putting a blank row before my insert and I've tried everything.... if($myvar != ''){ mysql_query("INSERT IGNORE INTO products (description, time) VALUES('$myvar',NOW() ) ") or die(mysql_error()); Similar TutorialsCode: [Select] <?php //Register 1.0.1 include("function.php"); connect(); $num = 0; if(isset($_POST['submit'])) { if($_POST['username'] == '' || $_POST['password1'] == '' || $_POST['password2'] == '') { $num = 1; echo "Please supply all fields;"; exit(); } elseif(strlen($_POST['username']) > 25) { $num = 1; echo "Username must be under 25 characters long;"; exit(); } elseif(strlen($_POST['password1']) > 16) { if(strlen($_POST['password2']) >16) { $num = 1; echo "Password are over 16 characters long;"; exit(); } $num = 1; echo "Passwords are not equal"; exit(); } elseif($_POST['password1'] != $_POST['password2']) { $num = 1; echo "Passwords are not equal;"; exit(); } } else { if(isset($_POST['submit'])) { $username = $_POST['username']; safe($username); if($_POST['password1'] = $_POST['password2']) { $password = $_POST['password']; password($password); echo "INSERT INTO user (username, password) VALUES ('$username','$password')"; } else { echo "Passwords are not equal; Double Take";//Yes Double Take is a military term exit(); } } } ?> <HTML> <form action="register.php" method="post"> Username:<input type="text" name="username"> <br> Password:<input type="password" name="password1"> <br> Password Check:<input type="password" name="password2"> <br> <input type="submit" name="submit" value="Register!"> </HTML> Here is where I put the code: if(isset($_POST['submit'])) { $username = $_POST['username']; safe($username); if($_POST['password1'] = $_POST['password2']) { $password = $_POST['password']; password($password); echo "INSERT INTO user (username, password) VALUES ('$username','$password')"; } else { echo "Passwords are not equal; Double Take";//Yes Double Take is a military term exit(); } I used it like that to narrow it down. And I still do not understand the issue, are there any other issues? [attachment deleted by admin] Ugh. Ive been asking so many questions, betcha already know my name. Hahah. Anyways, I know I already asked a question like this, but this is different. One of the values I am trying to insert into a database is simply not working. Here is the columnes in my mysql database: c_id commet story user date_added star Every value but 'commet' is getting inserted into database. NO error, no mysql errror. I have racked my brain trying to figure out what is wrong with the script. Here is my code: Code: [Select] <?php $idget = $_GET['id']; mysqlConnect(); //submit story if(isset($_POST['submit'])) { $com_form = mysql_real_escape_string(bb($_POST['commet'])); $rat_form = $_POST['rat']; $story_form = $idget; $user = $_SESSION['user']; $date = date("Y-m-d"); $query1 = " INSERT INTO story_commets(star, story, user, date_added, commet) VALUES($rat_form, '$story_form', '$user', '$date', '$com_form') "; mysql_query($query1) or die(mysql_error()); //} } // desplay reviews $query3 = " SELECT * FROM story_commets WHERE story = '$idget' ORDER BY date_added "; $select3 = mysql_query($query3) or die(mysql_error()); //$x=1; $ratav = array(); //if(mysql_num_rows($select3) == 0) //{ echo '<div id="message"> No Reviews Yet.... <>'; //} //else //{ while($rows3 = mysql_fetch_assoc($select3)) { $commetdb = $rows3['commet']; $user_com_db = $rows3['user']; $datedb = $rows3['date_added']; $stardb = $rows3['star']; //get profile picture $query4 = " SELECT * FROM login_info WHERE user = '$user_com_db' "; $select4 = mysql_query($query4) or die(mysql_error()); $rows4 = mysql_fetch_assoc($select4) or die(mysql_error()); $profile_pic = $rows4['profile_picture']; $user_id = $rows4['id']; echo " <div class='rev_cont'> <div class='info'> <img src='$profile_pic' /> <a href=?p=profile&id=$user_id> $user_com_db </a> <> <br /> <div class='rev'> <strong> $stardb/10 </strong> <br /> $commetdb <> <div id='date'> <em> Date Added: $datedb </em> <> <> <hr /> "; $ratav[]=$stardb; } $sum = array_sum($ratav); $count = count($ratav); $av = $sum / $count; $avf = round($av, 1); echo"<div id='message'> Rating Avarage: $avf /10 <>"; //} if (isset($_SESSION['user'])) { echo" <p> Did you like this story? Did you hate it? Give it a rating and let the author know!</p> <form action='?p=review&id=$idget' method='post' target='_self'> <label> Your rating is on a scale of 1-10 </label> <select name='rat'> <option> 1 </option> <option> 2 </option> <option> 3 </option> <option> 4 </option> <option> 5 </option> <option> 6 </option> <option> 7 </option> <option> 8 </option> <option> 9 </option> <option> 10 </option> </select> <label> Commets: </label> <textarea name='commet' cols='70' rows='9'></textarea> <input name='story' type='hidden' value='$idget' /> <br /> <input type='submit' value = 'Post' name='submit' /> </form> "; } else { echo "<div id='message'> Sign in to post a review! <>"; } ?> Here are the specifics if you want it. Here is the response part of the code: Code: [Select] <?php if(isset($_POST['submit'])) { $com_form = mysql_real_escape_string(bb($_POST['commet'])); $rat_form = $_POST['rat']; $story_form = $idget; $user = $_SESSION['user']; $date = date("Y-m-d"); $query1 = " INSERT INTO story_commets(star, story, user, date_added, commet) VALUES($rat_form, '$story_form', '$user', '$date', '$com_form') "; mysql_query($query1) or die(mysql_error()); //} } ?> Here is the form part of my code: Code: [Select] <?php if (isset($_SESSION['user'])) { echo" <p> Did you like this story? Did you hate it? Give it a rating and let the author know!</p> <form action='?p=review&id=$idget' method='post' target='_self'> <label> Your rating is on a scale of 1-10 </label> <select name='rat'> <option> 1 </option> <option> 2 </option> <option> 3 </option> <option> 4 </option> <option> 5 </option> <option> 6 </option> <option> 7 </option> <option> 8 </option> <option> 9 </option> <option> 10 </option> </select> <label> Commets: </label> <textarea name='commet' cols='70' rows='9'></textarea> <input name='story' type='hidden' value='$idget' /> <br /> <input type='submit' value = 'Post' name='submit' /> </form> "; } else { echo "<div id='message'> Sign in to post a review! <>"; } ?> Its probably something really mundane. HelP! Am a newbie in php. Since I can't insert values to the database with respect to a user Id or with any other token using WHERE clause. I.e "INSERT INTO receipts(date) VALUES(example) where id="**....." If I need to fetch several values of column for a particular user, how do I go about it? Thank you!!! I have a mysql table which will store users email addresses (each is unique and is the primary field) and a timestamp. I have added another column called `'unique_code' (varchar(64), utf8_unicode_ci)`. What I would very much appreciate assistance with is; a) Generating a 5 digit alphanumeric code, ie: 5ABH6 b) Check all rows the 'unique_code' column to ensure it is unique, otherwise re-generate and check again c) Insert the uniquely generated 5 digit alphanumeric code into `'unique_code'` column, corresponding to the email address just entered. d) display the code on screen. What code must I put and where? **My current php is as follows:** Code: [Select] require "includes/connect.php"; $msg = ''; if($_POST['email']){ // Requested with AJAX: $ajax = ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); try{ if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){ throw new Exception('Invalid Email!'); } $mysqli->query("INSERT INTO coming_soon_emails SET email='".$mysqli->real_escape_string($_POST['email'])."'"); if($mysqli->affected_rows != 1){ throw new Exception('You are already on the notification list.'); } if($ajax){ die('{"status":1}'); } $msg = "Thank you!"; } catch (Exception $e){ if($ajax){ die(json_encode(array('error'=>$e->getMessage()))); } $msg = $e->getMessage(); } } Hey guys, I have a private message script but for some reason when its updating, it turns the value into a blank one from 1 to 3. I have no idea why, but it works with the old statement of deleting, but I changed it to instead update it to 3 because I want to keep the pm in archives. here is the delete PM part. <?php session_start(); header("Location:inbox.php"); $user = $_SESSION['username']; include 'db.php'; //We do not have a user check on this page, because it seems silly to, you just send data to this page then it directs you right back to inbox //We need to get the total number of private messages the user has $sql = mysql_query ("SELECT pm_count FROM users WHERE username='$user'"); $row = mysql_fetch_array ($sql); $pm_count = $row['pm_count']; //A foreach loop for each pm in the array, get the values and set it as $pm_id because they were the ones selected for deletion foreach($_POST['pms'] as $num => $pm_id) { //Delete the PM from the database mysql_query("UPDATE messages SET recieved='3' WHERE id='$pm_id' AND reciever='$user'"); // mysql_query("DELETE FROM messages WHERE id='$pm_id' AND reciever='$user'"); //Subtract a private message from the counter! YAY! //$pm_count = $pm_count - '1'; //Now update the users message count with the new value //mysql_query("UPDATE users SET pm_count='$pm_count' WHERE username='$user'"); } ?> The commented out part at the end, is the old deleting parts but instead changed it to update value. Here is my form that shows checkboxes. I showed the whole code, where it has comments. <?php //This stuff and the while loop will query the database, see if you have messages or not, and display them if you do $query = "SELECT id, sender, subject, message FROM messages WHERE reciever='$user' AND recieved='1'"; $sqlinbox = mysql_query($query); //We have a mysql error, we should probably let somone know about the error, so we should print the error if(!$sqlinbox) { ?> <p><?php print '$query: '.$query.mysql_error();?></p> <?php } //There are no rows found for the user that is logged in, so that either means they have no messages or something broke, lets assume them they have no messages elseif (!mysql_num_rows($sqlinbox) ) { ?> <center><p><b>You havent read any messages</b></p></center> <?php } //There are no errors, and they do have messages, lets query the database and get the information after we make a table to put the information into else { //Ok, Lets center this whole table Im going to make just because I like it like that //Then we create a table 80% the total width, with 3 columns, The subject is 75% of the whole table, the sender is 120 pixels (should be plenty) and the select checkboxes only get 25 pixels ?> <center> <form name="send" method="post" action="delete.php"> <table width="80%"> <tr> <td width="75%" valign="top"><p><b><u>Subject</u></b></p></td> <td width="120px" valign="top"><p><b><u>Sender</u></b></p></td> <td width="25px" valign="top"><p><b><u>Select</u></b></p></td> </tr> <?php //Since everything is good so far and we earlier did a query to get all the message information we need to display the information. //This while loop goes through the array outputting all of the message information while($inbox = mysql_fetch_array($sqlinbox)) { //These are the variables we get from the array as it is going through the messages, we have the id of the private message, we have the person who sent the message, we have the subject of the message, and yeah thats it $pm_id = $inbox['id']; $sender = $inbox['sender']; $subject = $inbox['subject']; //So lets show the subject and make that a link to the view message page, we will send the message id through the URL to the view message page so the message can be displayed //And also let the person see who sent it to them, if you want you can make that some sort of a link to view more stuff about the user, but Im not doing that here, I did it for my game though, similar to the viewmsg.php page but a different page, and with the senders id //And finally the checkboxes that are all stuck into an array and if they are selected we stick the private message id into the array //I will only let my users have a maximum of 50 messages, remeber that ok? Because that's the value I will later in another page //Here is finally the html output for the message data, the while loop keeps going untill it runs out of messages ?> <tr> <td width="75%" valign="top"><p><a href="viewmsg.php?msg_id=<?php echo $pm_id; ?>"><?php echo $subject; ?></a></p></td> <td width="120px" valign="top"><p><?php echo $sender; ?></p></td> <td width="25px" valign="top"><input name="pms[]" type="checkbox" value="<?php echo $pm_id; ?>"></td> </tr> <?php //This ends the while loop } //Here is a submit button for the form that sends the delete page the message ids in an array ?> <tr> <td colspan="3"><input type="submit" name="Submit" value="Delete Selected"></td> <td></td> <td></td> </tr> </table> </center> <?php //So this ends the else to see if it is all ok and having messages or not } ?> So yeah, does anyone know why it updates it to a blank value, from the value 1 in recieved? <?php $PostID = mysql_escape_string($_GET['postid']); ?> <?php If ($_GET['CODE'] == '0') { $GetPostData = "SELECT * FROM ".FORUM_POSTS." WHERE post_id='{$PostID}'"; $GetPostRes = mysql_query($GetPostData, $db); $PostText = mysql_result($GetPostRes, 0, 'post_text'); $AuthorID = mysql_result($GetPostRes, 0, 'user_id'); If ($memid == $AuthorID || $MemLevel >= 1000) { ?> <div class="maintitle" align="left"><img src="./images/nav_m.gif" width="8" height="8"> Editing Post</div> <form action="index.php?act=edit&postid=<?php echo $PostID; ?>&CODE=1" method="POST"> <table width="100%" cellspacing="1" cellpadding="4"> <tr> <td class="titlemedium" colspan="2">Make changes below.</td> </tr> <tr> <td class="row2" align="right" width="15%" valign="top">Post Text:</td> <td class="row2" align="left" width="85%"> <textarea cols="80" rows="20" name="posttext"><?php echo $PostText; ?></textarea> </td> </tr> <tr><td class="row2" colspan="2" align="center"><input type="submit" value="Post" /></td></tr> </table> </form> <?php } Else { ?> <div class="maintitle" align="left"><img src="./images/nav_m.gif" width="8" height="8"> Error</div> <table width="100%" cellspacing="1" cellpadding="4"> <tr><td class="row2">You do not have the permission to edit this post.<br>If you believe this is an error please contact an administrator.</td></tr> </table> <?php } } If ($_GET['CODE'] == '1') { //Gather Information $PostText = mysql_escape_string($_POST['posttext']); $PostText = htmlentities($PostText); $PostID = mysql_escape_string($_GET['postid']); //Update Database $EditQry = "UPDATE ".FORUM_POSTS." SET post_text='{$PostText}' WHERE post_id='{$PostID}'"; $EditRes = mysql_query($EditQry, $db); //Check Data went in If (!$EditRes) { ?> <div class="maintitle" align="left"><img src="./images/nav_m.gif" width="8" height="8"> Error</div> <table width="100%" cellspacing="1" cellpadding="4"> <tr><td class="row2">Could not modify database. Please contact administrator.</td></tr> </table> <?php } Else { ?> <div class="maintitle" align="left"><img src="./images/nav_m.gif" width="8" height="8"> Success</div> <table width="100%" cellspacing="1" cellpadding="4"> <tr><td class="row2">Post modified. Please go back to the thread to see it.</td></tr> </table> <?php } } ?> </div> This is my page for editing a post. However, whenever this form actually goes through, the query for some reason makes post_text in the database blank with no text in it whatsoever. I have tried echoing the query to see what it says and it has a perfectly fine query and I can copy/paste it manually to put it into the mysql but I don't get why this isn't adding it. Hi
I have another problem with my code
I have records in my database and i want to put them in Jgrid but no records are show.
This is my php
<?php error_reporting(0); require_once 'database_connection.php'; $page = $_GET['page']; // get the requested page $limit = $_GET['rows']; // get how many rows we want to have into the grid $sidx = $_GET['sidx']; // get index row - i.e. user click to sort $sord = $_GET['sord']; // get the direction if(!$sidx) $sidx =1; // connect to the database $result = mysql_query("SELECT COUNT(*) AS count FROM utilizador"); $row = mysql_fetch_array($result,MYSQL_ASSOC); $count = $row['count']; if( $count >0 ) { $total_pages = ceil($count/$limit); } else { $total_pages = 0; } if ($page > $total_pages) $page=$total_pages; $start = $limit*$page - $limit; // do not put $limit*($page - 1) $SQL = "SELECT * FROM utilizador ORDER BY $sidx $sord LIMIT $start , $limit"; $result = mysql_query( $SQL ) or die("Couldn t execute query.".mysql_error()); $responce->page = $page; $responce->total = $total_pages; $responce->records = $count; $i=0; while($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $responce->rows[$i]['id']=$row[idutilizador]; $responce->rows[$i]['cell']=array($row[idutilizador],$row[nome],$row[utilizador],$row[telefone],$row[email]); $i++; } echo json_encode($responce); ?>And this is the Jgrid <html> <head> <title>jQGrid example</title> <!-- Load CSS--><br /> <link rel="stylesheet" href="css/ui.jqgrid.css" type="text/css" media="all" /> <!-- For this theme, download your own from link above, and place it at css folder --> <link rel="stylesheet" href="css/jquery-ui-1.9.2.custom.css" type="text/css" media="all" /> <!-- Load Javascript --> <script src="js/jquery_1.5.2.js" type="text/javascript"></script> <script src="js/jquery-ui-1.8.1.custom.min.js" type="text/javascript"></script> <script src="js/i18n/grid.locale-pt.js" type="text/javascript"></script> <script src="js/jquery.jqGrid.min.js" type="text/javascript"></script> </head> <body> <table id="datagrid"></table> <div id="navGrid"></div> <p><script language="javascript"> jQuery("#datagrid").jqGrid({ url:'example.php', datatype: "json", colNames:['Idutilizador','Nome', 'Utilizador', 'Telefone','Email'], colModel:[ {name:'idutilizador',index:'idutilizador', width:55,editable:false,editoptions:{readonly:true,size:10}}, {name:'nome',index:'nome', width:80,editable:true,editoptions:{size:10}}, {name:'idutilizador',index:'idutilizador', width:90,editable:true,editoptions:{size:25}}, {name:'telefone',index:'telefone', width:60, align:"right",editable:true,editoptions:{size:10}}, {name:'email',index:'email', width:60, align:"right",editable:true,editoptions:{size:10}} ], rowNum:10, rowList:[10,15,20,25,30,35,40], pager: '#navGrid', sortname: 'idutilizador', sortorder: "asc", height: 500, width:900, viewrecords: true, caption:"Atividades Registadas" }); jQuery("#datagrid").jqGrid('navGrid','#navGrid',{edit:true,add:true,del:true}); </script> </body> </html>Anything wrong with the code? Regards Hi there, I am using this code to send the users email address to the database. That works fine, but i keep getting blank info added to the database. Does anyone know how i can stop this? <?php $con = mysql_connect("*","*","*"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ogs_mailinglist1", $con); $sql="INSERT INTO mailinglist (email) VALUES ('$_POST[rec_email]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con); ?> Thanks, Wonder if someone can advise I have a script which runs on a CRON job, so every hour a script is activated. When the script runs, it INSERTS between 1 and 12 records into a database table, works a charm so far. When each QUERY is run on the script, it grabs the last ID number that was INSERTED and that is entered into another table, so if my script INSERTS a new row with an ID of 34877, then the ID number 34877 is entered into another database table. To grab the last ID number, I have always used $last_id = mysql_insert_id(); as seen on http://php.net/manual/en/function.mysql-insert-id.php which has always worked great. I now have to create another script on a CRON job, which does a similar TASK, it INSERTS a record into the same database and then grabs the last ID number. The plan is to roll about 150 of these script out, so each one is INSERTING data, and grabbing the last ID of the row just created. By 2015, they plan to have several thousand of these scripts, all being run at the same time. This is basically part of a bigger system and this is the method in which the 3rd party suppliers need data handled, so I have no option. My question is, if I have tons of scripts INSERTING data to the same database table and each time an INSERT is done, the last ID is grabbed, can PHP get overloaded and confused and then end up returning the wrong ID number of the row INSERTED. Or if I put $last_id = mysql_insert_id(); straight after each INSERT, then is it gurenteed that the right ID number is returned. Just concerned the QUERIES will end up in a que and incorrect ID numbers will be returned. Basically, is $last_id = mysql_insert_id(); flawless in getting the ID number of the row just INSERTED? Cheers everyone hi there, so okay i have a table named course which has 2 fields. c_id and c_name c_id here isn't unique but is indexed. okay,my problem is how to get the last inserted row in this table right after a record has been inserted. i was thinking i'd do a little query and then echo the results back to where the user fills up a form with c_id and c_name fields.. so is there a way to do this?like getting all values from the last inserted row? i have the following processing action for a form query DUMP output is: string(202) "INSERT INTO contactPO (Status, DateReceived, CustomerEmail, LastName, FirstName, PropertyID, fromdate, todate, nop) VALUES ('1', '24-08-2011', 'r', 'r', 'rrrrr', '12121', '27-10-2011', '30-10-2011','4')" but nothing is inserted Code: [Select] <?php $con = mysql_connect("localhost","international",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_query("SET NAMES 'utf8'"); mysql_select_db("international", $con); // check which button was clicked // perform calculation if ($_POST['send']) { $query = sprintf("INSERT INTO contactPO (Status, DateReceived, CustomerEmail, LastName, FirstName, PropertyID, fromdate, todate, nop) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s','%s')", mysql_real_escape_string($_POST['Status']), mysql_real_escape_string($_POST['DateReceived']), mysql_real_escape_string($_POST['CustomerEmail']), mysql_real_escape_string($_POST['LastName']), mysql_real_escape_string($_POST['FirstName']), mysql_real_escape_string($_POST['PropertyID']), mysql_real_escape_string($_POST['fromdate']), mysql_real_escape_string($_POST['todate']), mysql_real_escape_string($_POST['nop'])); var_dump($query ); //$url_success = "search-index.php?RID=".$_POST['RequestID'].""; $url_success = "search-index.php"; echo("<meta http-equiv = refresh content=6;url=".$url_success.">"); exit; mysql_close($con); } ?> Hi, I am making a website where the user can create a login and he's then redirected to the secured pages this is working ok. Then I want the user who's not yet completely registered to enter his full name and credentials and store this data in the table Owner. however when I am trying to do this with the below mentioned code I don't get any output on error level and I don't get any data inserted in my table what am I missing here Code: [Select] <?php //session starten session_start(); ini_set('display_errors', 'On'); error_reporting(E_ALL | E_STRICT); print_r($_SESSION['user_id']); //database verbinding maken mysql_connect("127.0.0.1", "root", "pass")or die("cannot connect"); mysql_select_db("tobysplace")or die("cannot select DB"); //kijken of de gebruikers_id al gekend is in de tabel Owner $result = mysql_query("Select gebruiker_id from Owner where gebruiker_id ='".mysql_real_escape_string($_SESSION['user_id'])"'"); If(!$result){ $gebruiker_id = mysql_insert_id(); } else { $gebruiker_id = mysql_real_escape_string($_SESSION['user_id']); } //de gegevens van de eigenaar wegschrijven in de database $Owner_query="insert into Owner( name, lastname, email, address1, town, postcode, phone, gebruiker_id)values( '" . mysql_real_escape_string($_SESSION['name']) . "', '" . mysql_real_escape_string($_SESSION['lastname']) . "', '" . mysql_real_escape_string($_SESSION['email']) . "', '" . mysql_real_escape_string($_SESSION['address1']) . "', '" . mysql_real_escape_string($_SESSION['town']) . "', '" . mysql_real_escape_string($_SESSION['postcode']) . "', '" . mysql_real_escape_string($_SESSION['phone']) . "', '" . mysql_real_escape_string($_SESSION['user_id']) ."')"; // // de query uitvoeren $result=mysql_query($Owner_query) //foutcontrole or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $Owner_query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error()); print '<p>'.$_SESSION['name'].' U bent met succes ingeschreven op tobys-place</p>'; //} ?> Basically the following code works fine, exepct when it comes to the last result it inserts it twice, example: (3,17),(4,17),(5,17),(5,17) Any clues as to why? Thanks Code: [Select] if(count($addIDs_ary) > 0) { $str = ""; foreach($addIDs_ary as $val) { $str .= "({$val},{$playerID}),"; if(end($addIDs_ary) == $val) { $str .= "({$val},{$playerID})"; } } echo $str; // (val,val), (val,val), (val,val) etc.. $query = "INSERT INTO hitlist (hit_id,player_id) values $str"; If the user signs up and does not have an avatar, a default will be given to them. I am checking for the avatar/image file, however, that is not working. Here is the messy code below: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // $username = $_POST['username']; // adds user info submitted upon registration to database function addUser($pdo) { $username = $_POST['username']; $password = password_hash($_POST['password'], PASSWORD_DEFAULT); $bio = $_POST['bio']; $email = $_POST['email']; $c_status = 0; $query = $pdo->prepare("INSERT into profiles001 (username, password, email, c_status, bio) VALUES (:username, :password, :email, :cstat, :bio)"); $query->bindValue(':username', $username); $query->bindValue(':password', $password); $query->bindValue(':email', $email); $query->bindValue(':cstat', $c_status); $query->bindValue(':bio', $bio); $file = $_FILES['userfile']; $file_name = $file['name']; $file_type = $file['type']; $file_size = $file['size']; $file_tmp_name = $file['tmp_name']; $file_error = $file['error']; if (!isset($_FILES['userfile'])) { $avatar = "assets/soap.jpg"; $avatar_present_query = $pdo->prepare("INSERT into profiles001 (avatar) VALUES (:avatar) WHERE username = ':username'"); $avatar_present_query->bindValue(':avatar', $avatar); $avatar_present_query->bindValue(':username', $username); $avatar_present_query->execute(); $query->execute(); } // $query->execute(); } addUser($pdo);
I have a small form, then after submit it inserts a new row with a few values (time, email) This form also sends email to the email from the form with a link. Problem, the link needs to contain an autoincrement value from the newly inserted row. How can I do this? (the form that obvioulsy doesn't work, for obviously reasons but to show what I try to accomplish:P) Code: [Select] <? if (isset($_REQUEST['Submit'])) { $time= time(); # THIS CODE TELL MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE $sql = "INSERT INTO phpfox_invite (user_id,email,time_stamp,is_used) values ('".$b."','".mysql_real_escape_string(stripslashes($_REQUEST['email']))."','".$time."','1')"; $sql = mysql_query("SELECT invite_id FROM phpfox_invite WHERE email='".mysql_real_escape_string(stripslashes($_REQUEST['email']))."'"); $result = mysql_fetch_array( $sql ); $inviteid = $result['invite_id']; if($result = mysql_query($sql)) { $modtager = "".mysql_real_escape_string(stripslashes($_REQUEST['email'])).""; $emne = "Please complete Your registration"; $besked = "Click the link below to complete your registration: \n http://domain.com/invite/id_".$inviteid." "; $header = "from:system@domain.com"; mail($modtager, $emne, $besked, $header); echo 'Check Your Email!'; } else { echo "ERROR: ".mysql_error(); } ?> Everything works ok, but ofcourse I cannot get the 'invite_id' before the form is submitted and therefor cannot send the value whats wrong in here for i get query failed everytime i submit the form? Code: [Select] //Create INSERT query $qry = "INSERT INTO class_members (user_name, passwrd, f_name, l_name, email, gender, date) VALUES('$user_name','".md5($_POST['password'])."','$f_name','$l_name','$email', '$gender','gmdate($date)',)"; $result = @mysql_query($qry); //Check whether the query was successful or not if($result) { header("location: register-success.php"); exit(); }else { die("Query failed"); } im playing around with a rating star jquery, i trying to get the value from the radio group but it is not selected??? Code: [Select] <?php require_once('Connections/international.php'); ?> <? mysql_query("SET NAMES 'utf8'")?> <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>jQuery Star Rating Plugin v3.13 (2009-03-26)</title> <script src='http://jquery-star-rating-plugin.googlecode.com/svn/trunk/jquery.js' type="text/javascript"></script> <script src='http://jquery-star-rating-plugin.googlecode.com/svn/trunk/documentation.js' type="text/javascript"></script> <link href='http://jquery-star-rating-plugin.googlecode.com/svn/trunk/documentation.css' type="text/css" rel="stylesheet"/> <script type="text/javaScript" src="http://www.fyneworks.com/jquery/project/chili/jquery.chili-2.0.js"></script> <script type="text/javascript">try{ChiliBook.recipeFolder="/jquery/project/chili/"}catch(e){}</script> <script src='http://jquery-star-rating-plugin.googlecode.com/svn/trunk/jquery.MetaData.js' type="text/javascript" language="javascript"></script> <script src='http://jquery-star-rating-plugin.googlecode.com/svn/trunk/jquery.rating.js' type="text/javascript" language="javascript"></script> <link href='http://jquery-star-rating-plugin.googlecode.com/svn/trunk/jquery.rating.css' type="text/css" rel="stylesheet"/> </head> <body> <a name="top"></a> <div id="wrap"> <div id="body"> <div id="documentation" class="tabs"> <div id="tab-Testing"> <h2>Test Suite</h2> <script type="text/javascript" language="javascript"> $(function(){ $('#form1 :radio.star').rating(); $('#form2 :radio.star').rating({cancel: 'Cancel', cancelValue: '0'}); $('#form3 :radio.star').rating(); $('#form4 :radio.star').rating(); }); </script> <script> $(function(){ $('#tab-Testing form').submit(function(){ $('.test',this).html(''); $('input',this).each(function(){ if(this.checked) $('.test',this.form).append(''+this.name+': '+this.value+'<br/>'); }); return false; }); }); </script><div class="Clear"> </div> <form name="form1" id="form1" method="POST"> <strong style='font-size:150%'>Test 2</strong> - With defaults ('checked') <table width="100%" cellspacing="10"> <tr> <td valign="top" width=""> <table width="100%"> <tr> <td valign="top" width="50%"> <div class="Clear"> Rating 1: (N/M/Y, default M) </div> <div class="Clear"> <input class="star" type="radio" name="rating1" value="0" id="rating1_0" title="0"/> <input class="star" type="radio" name="rating1" value="1" id="rating1_1" title="1"/> <input class="star" type="radio" name="rating1" value="2" id="rating1_2" title="2"/> </div> <div class="Clear"> Rating 2: (10 - 50, default 30) </div> <div class="Clear"> <input class="star" type="radio" name="rating22" value="10"/> <input class="star" type="radio" name="rating22" value="20"/> <input class="star" type="radio" name="rating22" value="30" checked="checked"/> <input class="star" type="radio" name="rating22" value="40"/> <input class="star" type="radio" name="rating22" value="50"/> </div> <div class="Clear"> Rating 3: (1 - 7, default 4) </div> <div class="Clear"> <input class="star" type="radio" name="rating23" value="1"/> <input class="star" type="radio" name="rating23" value="2"/> <input class="star" type="radio" name="rating23" value="3"/> <input class="star" type="radio" name="rating23" value="4" checked="checked"/> <input class="star" type="radio" name="rating23" value="5"/> <input class="star" type="radio" name="rating23" value="6"/> <input class="star" type="radio" name="rating23" value="7"/> </div> </td> <td valign="top" width="50%"> <div class="Clear"> Rating 4: (1 - 5, default 1) </div> <div class="Clear"> <input class="star" type="radio" name="rating24" value="1" title="Worst" checked="checked"/> <input class="star" type="radio" name="rating24" value="2" title="Bad"/> <input class="star" type="radio" name="rating24" value="3" title="OK"/> <input class="star" type="radio" name="rating24" value="4" title="Good"/> <input class="star" type="radio" name="rating24" value="5" title="Best"/> </div> <div class="Clear"> Rating 5: (1 - 5, default 5) </div> <div class="Clear"> <input class="star" type="radio" name="rating25" value="1"/> <input class="star" type="radio" name="rating25" value="2"/> <input class="star" type="radio" name="rating25" value="3"/> <input class="star" type="radio" name="rating25" value="4"/> <input class="star" type="radio" name="rating25" value="5" checked="checked"/> </div> <div class="Clear"> Rating 6 (readonly): (1 - 5, default 3) </div> <div class="Clear"> <input class="star" type="radio" name="rating26" value="1" disabled="disabled"/> <input class="star" type="radio" name="rating26" value="2" disabled="disabled"/> <input class="star" type="radio" name="rating26" value="3" disabled="disabled" checked="checked"/> <input class="star" type="radio" name="rating26" value="4" disabled="disabled"/> <input class="star" type="radio" name="rating26" value="5" disabled="disabled"/> </div> </td> </tr> </table> </td> <td valign="top" width="5"> </td> <td valign="top" width="50"> <input type="submit" value="Submit" name="submit"/> </td> <td valign="top" width="5"> </td> <td valign="top" width="160"> <u>Test results</u>:<br/><br/> <div class="test Smaller"> <span style="color:#FF0000">Results will be displayed here</span> </div> </td> </tr> </table> <script> $(function(){ $('.hover-star').rating({ focus: function(value, link){ // 'this' is the hidden form element holding the current value // 'value' is the value selected // 'element' points to the link element that received the click. var tip = $('#hover-test'); tip[0].data = tip[0].data || tip.html(); tip.html(link.title || 'value: '+value); }, blur: function(value, link){ var tip = $('#hover-test'); $('#hover-test').html(tip[0].data || ''); } }); }); </script> <div class="Clear"> </div><div class="Clear"> </div> </div> </div> </div> <div id="push"></div> </div> </form> </body></html> <?php mysql_select_db($database_international, $international); $query=mysql_query("INSERT INTO ratings_tbl (Comfort) VALUES ('$_POST[rating1]'')"); $selected_radio = $_POST['rating1']; echo $selected_radio; var_dump($_POST); ;?> I only see one "mysql_query($memberquery);" Yet the record is inserted 4 times when I check the db. Anyone see why? Thank you for your time! Code: [Select] <?php $link_register = 1; session_start(user); include("header.php"); $firstname = $_SESSION['firstname']; $middleinitial = $_SESSION['middleinitial']; $lastname = $_SESSION['lastname']; $phone = $_SESSION['phone']; $email = $_SESSION['email']; $street = $_SESSION['street']; $city = $_SESSION['city']; $state = $_SESSION['state']; $categoryArray = $_SESSION['categoryArray']; $gender = $_SESSION['gender']; $con = mysql_connect("localhost", "root", ""); if (!$con) { die("Could not connect: ". mysql_error()); } //The database is selected with the mysql_select_db() function. mysql_select_db("hobbyclub", $con); //put the data insert into a varaible so it can be checked later $memberquery = "INSERT INTO member (firstname, middleinitial, lastname, phone, email, street, city, state, gender) VALUES ('$firstname', '$middleinitial', '$lastname', '$phone', '$email', '$street', '$city', '$state', '$gender')"; // if ($categoryArray){ // foreach ($categoryArray as $category){ // $categoryString .= "'$".$category."',"; // } // } // $categoryquery = "INSERT INTO category (categoryname) VALUES('$categoryString')"; // $categoryquery = "INSERT INTO category (categoryname) VALUES(".$categoryString.")"; //insert the data mysql_query($memberquery); ?> The commented out block of code is just me trying to figure out how to insert an array into the db. Hi Guys, actually I'm doing hard with this code. the fact is that Im inserting data (name, phone number, nss) and im doing a select to get the id number where nss is like $nss (. I don`t know why I can`t receive data, i think the fact is that all the code is inside an if statement) But that is why im here guys. In adittion I tryed to get the max id in order to print into mail function. But I couldn't . This is my code...
************************************************************************************************************ //Database connection done perfectly $mysqli = mysqli_connect( "****", "***", "***", "***");
************************************************************************************************************ // Im working with bots and the intent received is this, in addition i get variables correctly.
************************************************************************************************************ //here im inserting the variables in the correct order. The database is getting the values correctly too.
************************************************************************************************************
************************************************************************************************************
//here is the section when im going to select the id from the table, where the nss number is equal to the nss variable number that i've putted (but idk if the insert is done at this point....
************************************************************************************************************ For example i'm getting the mail, the name and lastname correctly from my function (which gets the parameters and turn the information in readable characters to php)
$to = $email; } ************************************CODE DONE ***********************************************************
So guys, Idk what is happening here, I tryed lot of things but when im get the email I dont get the id value..... I think is because the insert hasn't been completed while the if is open..... In adition I wanto to ask you guys if somebody knows how to get correctly the data from this code... Firstly I was trying to get the max id from my table and then plus 1 to increase the number. and in that order put the id by myself or atleast get the value in that way. I tryed closely, but i finish getting the array value.. I going to show my code...
function obtener_Id(){ I have tried to run my code and it works. I am not getting any error message but when I checked my database nothing was added. Code: [Select] <?php session_start(); include '../Database/connection.php'; if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } $filename = $_FILES["file"]["tmp_name"]; $fd = fopen ($filename, "r"); $data = fread ($fd,filesize ($filename)); fclose ($fd); $delimiter = "\n"; $output = explode($delimiter, $data); foreach($output as $var) { $tmp = explode(".", $var); $question = $tmp[0]; $choice1 = $tmp[1]; $choice2 = $tmp[2]; $choice3 = $tmp[3]; $choice4 = $tmp[4]; $answer1 = $tmp[5]; $answer2 = $tmp[6]; $answer3 = $tmp[7]; $answer4 = $tmp[8]; $sql = "INSERT INTO question SET Que_Question='$question', Que_Choice1='$choice1', Que_Choice2='$choice2', Que_Choice3='$choice3', Que_Choice4='$choice4', Que_Answer1='$answer1', Que_Answer2='$answer2', Que_Answer3='$answer3', Que_Answer4='$answer4', Tes_ID='$_SESSION[Tes_ID]'"; mysql_query($sql); } ?> My text file holds Quote What is the sky.where.how.wen.one.0.0.1.0 What colour.where.what.how.more.0.0.1.0 |