Jump to content

yandoos

Members
  • Posts

    35
  • Joined

  • Last visited

yandoos's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you that has done it - specifying the fields. Thank you for explaining about real_escape_string() too, I didn't know that. Thank you very much
  2. <?php $per_page='10'; if (isset($_GET['page'])) { $page = $_GET['page']; }else { $page='1';} // Page will start from 0 and Multiple by Per Page $start_from = ($page-1) * $per_page; $connection = mysqli_connect($dbhost_name, $username, $password, $database); $finder1 = mysqli_query($connection,"SELECT * FROM product left join distribution ON product.pid = distribution.pid left join plus_signup ON distribution.mem_id = plus_signup.mem_id LIMIT $start_from, $per_page") or die (mysql_error()); $connection = mysqli_connect($dbhost_name, $username, $password, $database); $counter1 = mysqli_query($connection,"SELECT * FROM product left join distribution ON product.pid = distribution.pid left join plus_signup ON distribution.mem_id = plus_signup.mem_id") or die (mysql_error()); // Count the total records $total_records = mysqli_num_rows($counter1); //Using ceil function to divide the total records on per page $total_pages = ceil($total_records / $per_page); } echo '<table class="admintable" width="1000" style="padding:0px 10px 0px 10px;" border="0">'; while($builder1 = mysqli_fetch_array($finder1)) { $pid = mysqli_real_escape_string($connection, $builder1['pid']); echo $pid; echo '<br/>'; echo'<tr><td valign="top">'; ?> <table border="0"><tr><td width="100"> <form action="update_image.php" enctype="multipart/form-data" method="post"> <input name="pid" type="hidden" value="<?php echo $builder1['pid'];?>"> Name: </td><td><input name="productname" type="text" value="<?php echo $builder1['productname'];?>"></td></tr><tr> <td>Price: </td><td><input name="price" type="text" value="<?php echo $builder1['price'];?>"></td></tr><tr> <td> Stock: </td><td><input name="stock" type="text" value="<?php echo $builder1['stock'];?>"></td></tr><tr> <?php echo '<tr><td colspan="2">'; if ($builder1['name'] != NULL){ echo 'Product assigned to: <a href="http://dusousbois.co.uk/distributions.php?id='; echo $builder1['pdid']; echo '">'; echo $builder1['name']; echo '</a>'; } else if ($builder1['name'] == NULL){ echo 'Product ready for assigment'; } echo'</td></tr>'; ?> <td colspan="2">Description:<br/><textarea name="description" cols="40" rows="8"><?php echo $builder1['description'];?></textarea></td></tr><tr> <td><input name="submit" type="Submit" value="Edit Product"/></td> <td> <?php if ($builder1['stock'] == '1') { echo $pid; echo '<a href="delete_products.php?id='; echo $builder1['pid']; echo'">Delete</a>'; } else if ($builder1['stock'] == '0') { echo 'This product can not be deleted as it has been assigned to a gallery'; } echo '</td></tr>';} echo' </table>'; Here is a snipped of the code in question. The problem is that the $pid is not outputting when the mem_id is NULL
  3. Sorry I was using left join. The results are the same as in the attachment and on page. I was trying all the other joins to see if it would work to no avail.
  4. Hello I was hoping some help with joining tables.... I have joined tables but have found strange results so i assume I am doing it wrong. Whats happening is that even though I am pulling the query from the product table if there are NULL data in the mem_id field the row is not being pulled. I would add this is using a php while loop, using phpmyadmin and pure mysql it works. SELECT * FROM product join distribution ON product.pid = distribution.pid join plus_signup ON distribution.mem_id = plus_signup.mem_id Have a look at this phpmyadmin screen shot. The records for pid 3, and 4 are not being outputted when I used a php while loop. I need it so that all the records will be pulled even if the mem_id is null. Is there a way I can do this? Thank you
  5. Hello i was really hoping for some help with a select query. Before I explain the issue here is the background. I have 3 tables - products, clients, distributions product table pid productname description price client table cid name age distribution table pdid pid* cid* status date I am in the process of building the add distribution form and want to use a select query that will dynamically show the options in a dropdown and join the 3 tables. SELECT name, client.cid FROM distribution join product ON distribution.pid = product.pid join client ON distribution.cid = client.cid echo '<option value="'.$build['cid'].'">'.$build['name'].'</option>'; Here is the problem... I want ONLY to select the cid and name from the distribution table that has less than 10 records. This is because a client can have only a maximum of 10 distribution records. So I only want these clients to appear as options in the dropdown as opposed to all the clients names and cids. I really don't know how to achieve this so any help would be ace. Thank you
  6. I realised the date needed to be reformatted before it could be updated in the db. $pdid = $_POST['pdid']; $delivery_date1 = $_POST['delivery_date']; $status = $_POST['status']; $start1 = $_POST['start']; $ending1 = $_POST['end']; $balance = $_POST['balance']; $delivery_date = date_create($delivery_date1)->format('Y-m-d'); $start = date_create($start1)->format('Y-m-d'); $ending = date_create($ending1)->format('Y-m-d'); Thank you
  7. The structure type of the date fields are set as Date. Could this be causing the problem?
  8. That makes me think I have forgotten to add the $connection to it: $result = mysqli_query($connection, $sql); If I change it as above there is no error again...
  9. if I add $result = mysqli_query($sql); I get an error: Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/dusousbo/public_html/update_distributions.php on line 37 $connection = mysqli_connect($dbhost_name, $username, $password, $database); $sql = mysqli_query($connection,"UPDATE distribution SET delivery_date = '$delivery_date', status = '$status', start = '$start', end = '$ending', balance = '$balance' WHERE pdid = '$pdid'" )or die (mysql_error()); $result = mysqli_query($sql); echo $sql; echo $result;
  10. Thanks for the reply, I've added or die (mysql_error()); to the query and if I echo $sql; It displays 1. $connection = mysqli_connect($dbhost_name, $username, $password, $database)or die('Could not connect: ' . mysqli_connect_error()); $sql = mysqli_query($connection,"UPDATE distribution SET delivery_date = '$delivery_date', status = '$status', start = '$start', end = '$ending', balance = '$balance' WHERE pdid = '$pdid'" )or die (mysql_error()); echo $sql;
  11. I've been staring at this for ages now and just don't see what the problem is. I have an update query that updates records in the db. It only updates some of the fields and ignores all the date fields. I've echoed out variables and they are all correct but they just dont update and there is no error either? <?php ini_set('display_errors', 1); error_reporting(E_ALL); include "include/session.php"; require('config.php'); require('include/functions.php'); if (isset($_POST['Submit1'])) { echo 'cheese'; $pdid = $_POST['pdid']; $delivery_date = $_POST['delivery_date']; $status = $_POST['status']; $start = $_POST['start']; $ending = $_POST['end']; $balance = $_POST['balance']; } echo $pdid; echo '<br>'; echo $delivery_date; echo '<br>'; echo $status; echo '<br>'; echo $start; echo '<br>'; echo $ending; echo '<br>'; echo $balance; echo '<br>'; echo $pdid; echo '<br>'; $connection = mysqli_connect($dbhost_name, $username, $password, $database); $result = mysqli_query($connection, "UPDATE distribution SET delivery_date = '$delivery_date', status = '$status', start = '$start', end = '$ending', balance = '$balance' WHERE pdid = '$pdid'"); echo 'done'; ?> What am I doing wrong? Thanks
  12. Hello I'm using a nice datepicker that I want to use on text fields pulled form the database. The things is at the moment only the first row of results (which consists of 3 datepicker fields) actually work with it. I really need to know how to integrate it within the while loop so each row uses the datepicker functionality. Any chance you can help me please? <head> <title>Admin Area - Distributions</title> <!--[if IE]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]--> <link href="css/style.css" rel="stylesheet" type="text/css"> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <script> $(function() { $( "#datepicker" ).datepicker(); }); $(function() { $( "#datepicker1" ).datepicker(); }); $(function() { $( "#datepicker2" ).datepicker(); }); </script> </head> $data = mysqli_query($connection," SELECT name, productname, pdid, description, image1, image2, image3, price, status, delivery_date, start, end, ref, balance FROM distribution join product ON distribution.pid = product.pid join plus_signup ON distribution.mem_id = plus_signup.mem_id") or die (mysql_error()); while($build = mysqli_fetch_array($data)) { ?> <table><tr><td><form action="update_distributions.php" enctype="multipart/form-data" method="post"> <input name="pdid" type="hidden" value="<?php echo $build['pdid'];?>" /> Status: </td><td><select name="status"> <option selected="selected"><?php echo $build['status']; ?></option> <option value="Accepted">Accepted</option> <option value="Complete">Complete</option> <option value="Damaged">Damaged</option> <option value="Delivered">Delivered</option> <option value="Offered">Offered</option> <option value="Sold">Sold</option> </select></td></tr> <tr><td>Balance:</td> <td><input name="balance" type="text" value="<?php echo $build['balance'];?>" /></td></tr> <tr><td>Delivery Date:</td> <td><input name="delivery_date" type="text" value="<?php echo $build['delivery_date'];?>" id = "datepicker2" /></td></tr> <tr><td>Start Date:</td> <td><input name="start" type="text" value="<?php echo $build['start'];?>" id = "datepicker" /></td></tr> <tr><td>End Date:</td> <td> <input name="end" type="text" value="<?php echo $build['end'];?>" id = "datepicker1" /></td></tr> <tr><td colspan="2" align="right"><Input type = "Submit" Name = "Submit1" id="mysubmit" VALUE = "Submit" ></td></tr></table> </form> <?php } ?> Thank you
  13. Hello I'm really not sure what going on but I;m trying to insert a record but it's not working. i just get a white screen. Can you see what the problem is and advise me how to fix it please? <form action="add_galleries.php" enctype="multipart/form-data" method="post"> <input name="mem_id" type="hidden"> <input name="userid" type="text"> <input name="name" type="text"> <input name="email" type="text"> <select name="user_level"> <option value="0">Regular</option> <option value="1">Admin</option> </select> <input name="pass" type="password"> <input name="submit" type="Submit" value="Add New Gallery"/> </form> and the insert query: <?php ini_set('display_errors', 1); error_reporting(E_ALL); include "include/session.php"; require('config.php'); require('include/functions.php'); if (isset($_POST['submit'])) { $pass = $_POST['pass']; $pass1 = md5($pass); $name = mysqli_real_escape_string(mysqli $link, $_POST['name']); $email = mysqli_real_escape_string(mysqli $connection, $_POST['email']); $user_level = mysqil_real_escape_string(mysqli $connection, $_POST['user_level']); $userid = mysqli_real_escape_string(mysqli $connection, $_POST['userid']); $pass2 = mysqli_real_escape_string(mysqli $connection, $_POST['pass1']); echo $name; echo'<br/>'; echo $userid; echo '<br/>'; echo $email; echo'<br/>'; echo $user_level; echo'<br/>'; echo $pass1; echo'<br/>'; $connection = mysqli_connect($dbhost_name, $username, $password, $database); $sql = mysqli_query($connection,"INSERT INTO plus_signup (name, userid, user_level, password, email) VALUES ('$name', '$userid', '$user_level', '$pass2', '$email'"); $result = mysqli_query($connection,$sql) or die (mysql_error()); } ?> Thank you
  14. The only way I can think of doing this is using the following if else statements but there must be a better way: if ($pic == NULL && $pic1 != NULL && $pic2 != NULL) { } else if ($pic == NULL && $pic1 == NULL && $pic2 != NULL) { } else if ($pic == NULL && $pic1 == NULL && $pic2 == NULL) { } else if ($pic != NULL && $pic1 == NULL && $pic2 == NULL) { } else if ($pic != NULL && $pic1 != NULL && $pic2 == NULL) { } else if ($pic != NULL && $pic1 != NULL && $pic2 != NULL) { }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.