Search the Community
Showing results for tags 'php/mysql'.
-
Hi I am very new to PHP & Mysql. I am trying to insert values into two tables at the same time. One table will insert a single row and the other table will insert multiple records based on user insertion. Everything is working well, but in my second table, 1st Table ID simply insert one time and rest of the values are inserting from 2nd table itself. Now I want to insert the first table's ID Field value (auto-incrementing) to a specific column in the second table (only all last inserted rows). Ripon. Below is my Code: <?php $con = mysql_connect("localhost","root","aaa"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ccc", $con); $PI_No = $_POST['PI_No']; $PO_No = $_POST['PO_No']; $qry = "INSERT INTO wm_order_entry ( Order_No, PI_No, PO_No) VALUES( NULL, '$PI_No', '$PO_No')"; $result = @mysql_query($qry); $val1=$_POST['Size']; $val2=$_POST['Style']; $val3=$_POST['Colour']; $val4=$_POST['Season_Code']; $val5=$_POST['Dept']; $val6=$_POST['Sub_Item']; $val7=$_POST['Item_Desc']; $val8=$_POST['UPC']; $val9=$_POST['Qty']; $N = count($val1); for($i=0; $i < $N; $i++) { $profile_query = "INSERT INTO order_entry(Size, Style, Colour, Season_Code, Dept, Sub_Item, Item_Desc, UPC, Qty, Order_No ) VALUES( '$val1[$i]','$val2[$i]','$val3[$i]','$val4[$i]','$val5[$i]','$val6[$i]','$val7[$i]','$val8[$i]','$val9[$i]',LAST_INSERT_ID())"; $t_query=mysql_query($profile_query); } header("location: WMView.php"); mysql_close($con); ?> Output is attached. Here i want in my second row my Order_No should be 170 instead of 38.
-
Hello to every one: I very new to PHP/MYSQL. I created mysql table( Please see image) can i generate report like those image attached? Please help. Emel
-
hi..... I m new in php.i have syntax error, unexpected '}' in C:\wamp\www\emailsubunsub\manage.php on line 59 error in my snippet.if anyone fi bug or suggest me same then it would be great help for me. <?php include 'subscribe_include.php'; //determine if they need to see the form or not if(!$_POST){ //they need to see the form,so create the form block $display_block=<<<END_OF_BLOCK <form method='POST' action-"$_SERVER[PHP_SELF]"> Your E-mail address : <input type="email" id="email" name="email" size="40" maxlength="150"/> <fieldset> <legend>Action :</legend><br/> Subscribe : <input type="radio" id="action_sub" name="action" value="sub" checked/><br/> Unsubscribe : <input type="radio" id="action_unsub" name="action" value="unsub"/> </fieldset> <button type="submit" name="submit" value="submit">Submit</button> </form> END_OF_BLOCK; } else if(($_POST)&&($_POST['action']=="sub")){ //trying to subscribe;validate e-mail address if(($_POST['email']==" ")){ header("Location:manage.php"); exit;} else{ //connect to database doDB(); //check that mail is in list emailChecker($_POST['email']); //get number of results and do action if(mysqli_num_rows($check_res)<1){ //free result mysqli_free_result($check_res); //add record $add_sql="INSERT INTO Subscribers_DB(email) VALUES ('".$safe_email."')"; $add_res=mysqli_query($mysqli,$add_sql) or die(mysqli_error($mysqli)); $display_block="<p>Thanks for signing up</p>"; //close connection to mysql mysqli_close($mysqli); } else{ //print failure message $display_block="<p>You are already subscribed!</p>" } } } else if(($_POST)&&($_POST['action']=="unsub")){ //trying to unsubscribe;validate e-mail address if($_POST['email']==""){ header("Location:manage.php"); exit; } else{ //connect to database doDB(); //check that email is in list emailChecker($_POST['email']); //get number of results and do action if(mysqli_num_rows($check_res)<1){ //free result mysqli_free_result($check_res); //print failure message $display_block="<p>Couldn,t find your address!</p><p>No action was taken</p>"; } else{ //get value of id from result while($row=mysqli_fetch_array($check_res)){ $id=$row['id']; } //unsubscribe the address $del_sql="DELETE FROM Subscribers_db WHERE id=".$id; $del_res=mysqli_query($mysqli,$del_sql)or die(mysqli_error($mysqli)); $display_block="<p>You're unsubscribed!</p>"; } mysqli_close($mysqli); } } ?> <html> <head> <title>Subscribe/Unsubscribe to a mailing list</title> </head> <body> <h1>Subscribe/Unsubscribe to a mailing list</h1> <?php echo "$display_block";?> </body> </html>
-
Hello, I am working on a personal project which is to generate a set of unique codes and store them in a database. The concept of the project is for me to be able to determine the numbers of codes I want to generate and insert each of them into the database. I have been able to come up with something with the help of a tutorial which is working but not inputting into database and it allows one generation at a time. Please see my code below $username = "root"; $password = "password"; $hostname = "localhost"; $database = "gencode"; $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db($database,$dbhandle) or die("Could not select $database"); $unique_ref_length = 11; $unique_ref_found = false; $possible_chars = "23456789ABCDFGHJKLMNPQRSTWXYZ"; while (!$unique_ref_found) { $unique_ref = ""; $i = 0; while ($i < $unique_ref_length) { $char = substr($possible_chars, mt_rand(0, strlen($possible_chars)-1), 1); $unique_ref .= $char; $i++; } $query = "SELECT `order_ref_no` FROM `orders` WHERE `order_ref_no`='".$unique_ref."'"; $result = mysql_query($query) or die(mysql_error().' '.$query); if (mysql_num_rows($result)==0) { $unique_ref_found = true; } } echo 'Our unique reference number is: '.$unique_ref; Your assistance will be greatly appreciated.